package org.netty.framework.core.util;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.netty.framework.core.annotation.HandlerExecutionChain;
import org.netty.framework.core.codec.CustomMsg;
import org.netty.framework.core.codec.CustomMsgDecoder;

/**
 * 自定义注解的容器
 * 
 * @author chenfanglin
 * @date 2018年10月8日下午6:17:49
 */
public class AnnotationContainer {

	/**
	 * http请求url映射map
	 */
	private static Map<String, HandlerExecutionChain> handleMappers = new ConcurrentHashMap<String, HandlerExecutionChain>();

	/**
	 * tcp请求cmd映射处理器map
	 */
	private static Map<Long, HandlerExecutionChain> processMappers = new ConcurrentHashMap<Long, HandlerExecutionChain>();

	/**
	 * tcp请求cmd映射解码器map
	 */
	private static Map<Long, CustomMsgDecoder<CustomMsg<?>>> decoderMappers = new ConcurrentHashMap<Long, CustomMsgDecoder<CustomMsg<?>>>();

	/**
	 * websocket请求url映射map
	 */
	private static Map<String, HandlerExecutionChain> webSocketMappers = new ConcurrentHashMap<String, HandlerExecutionChain>();

	/**
	 * 根据cmd获取解码器
	 * 
	 * @param cmd
	 * @return
	 */
	public static CustomMsgDecoder<CustomMsg<?>> getDecoder(Long cmd) {
		return decoderMappers.get(cmd);
	}

	/**
	 * 存放解码器到容器
	 * 
	 * @param cmd
	 * @param decoder
	 */
	public static void putDecoder(Long cmd, CustomMsgDecoder<CustomMsg<?>> decoder) {
		decoderMappers.put(cmd, decoder);
	}

	/**
	 * 根据url获取HandlerExecutionChain
	 * 
	 * @param url
	 * @return
	 */
	public static HandlerExecutionChain getHandle(String url) {
		return handleMappers.get(url);
	}

	/**
	 * 存放HandlerExecutionChain到容器
	 * 
	 * @param url
	 * @param handle
	 */
	public static void putHandle(String url, HandlerExecutionChain handle) {
		handleMappers.put(url, handle);
	}

	/**
	 * 根据cmd获取请求的处理器
	 * 
	 * @param cmd
	 * @return
	 */
	public static HandlerExecutionChain getProcess(long cmd) {
		return processMappers.get(cmd);
	}

	/**
	 * 存放处理器到容器
	 * 
	 * @param cmd
	 * @param process
	 */
	public static void putProcess(long cmd, HandlerExecutionChain process) {
		processMappers.put(cmd, process);
	}

	/**
	 * 根据url获取websocket的处理handle
	 * 
	 * @param url
	 * @return
	 */
	public static HandlerExecutionChain getWebSocketHandle(String url) {
		return webSocketMappers.get(url);
	}

	/**
	 * 存放HandlerExecutionChain到容器
	 * 
	 * @param url
	 * @param handle
	 */
	public static void putWebSocketHandle(String url, HandlerExecutionChain handle) {
		webSocketMappers.put(url, handle);
	}

}
